﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Configuration;
using Windows.Foundation;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Shapes = Windows.UI.Xaml.Shapes;

namespace BoolanElement
{
    public class BooRightTriangle:BooTextShapesBase
    {
        Shapes.Polygon rightTriangle;
        public Shapes.Polygon RightTriangle 
        {
            get 
            {
                return rightTriangle;
            }
            set
            {
                rightTriangle = value;
            }
        }

        BooRightTriangleElement rightTriangleElement;
        public BooRightTriangleElement RightTriangleElement 
        {
            get { return rightTriangleElement; }
        }

        public override BooElement Element
        {
            set { rightTriangleElement = (BooRightTriangleElement)value; }
            get { return rightTriangleElement; }
        }

        public override BooTextShapesBaseElement TextShapesBaseElement
        {
            get { return rightTriangleElement; }
        }

        public override Shapes.Shape Shape
        {
            get { return rightTriangle; }
        }
        public BooRightTriangle(BooRightTriangleElement rightTriangleElement, SaveForRedoUndo saveForRedoUndo)
            : base(rightTriangleElement)
        {
            this.rightTriangleElement = rightTriangleElement;
            InitOriginal();
            base.saveForRedoUndo = saveForRedoUndo;
            Focus.InitFocusEvent(this);
        }

        public BooRightTriangle(BooRightTriangleElement rightTriangleElement)
            : base(rightTriangleElement)
        {
            this.rightTriangleElement = rightTriangleElement;
            InitOriginalForThumbNails();
        }

        public override void InitShape()
        {
            rightTriangle = new Shapes.Polygon();
            rightTriangle.Points = BooShapesPoints.CopyPointCollection(this.rightTriangleElement.Points);
            rightTriangle.ManipulationMode = ManipulationModes.All;
        }

        public override void ReSizeUI(double x, double y)
        {
            if (rightTriangleElement.ElementTransform.Width + x < 50 || rightTriangleElement.ElementTransform.Height + y < 50)
            {
                return;
            }

            rightTriangleElement.ElementTransform.Width = rightTriangleElement.ElementTransform.Width + x;
            rightTriangleElement.ElementTransform.Height = rightTriangleElement.ElementTransform.Height + y;

            rightTriangleElement.PropertyChanged("Shape");
        }

        public override void ReMargin(double x, double y)
        {
            this.Element.ElementTransform.Translate.X += x;
            this.Element.ElementTransform.Translate.Y += y;
        }


        public override void ApplySize()
        {
            base.ApplySize();
            rightTriangleElement.ShapeWidth = rightTriangleElement.ElementTransform.Width;
            rightTriangleElement.ShapeHeight = rightTriangleElement.ElementTransform.Height;

            //this.rightTriangle.Width = rightTriangleElement.ElementTransform.Width;
            //this.rightTriangle.Height = rightTriangleElement.ElementTransform.Height;

            FullGrid.Width = rightTriangleElement.ElementTransform.Width;
            FullGrid.Height = rightTriangleElement.ElementTransform.Height;

            //BooCanvas.Width = rightTriangleElement.ElementTransform.Width;
            //BooCanvas.Height = rightTriangleElement.ElementTransform.Height;

            CenterStack.Width = rightTriangleElement.ElementTransform.Width;
            //CenterStack.MaxHeight = rightTriangleElement.ElementTransform.Height;


            this.TextBox.Width = rightTriangleElement.ElementTransform.Width;
            rightTriangleElement.TextWidth = rightTriangleElement.ElementTransform.Width;
           // this.TextBox.MaxHeight = rightTriangleElement.ElementTransform.Height;
           // rightTriangleElement.TextMaxHeight = rightTriangleElement.ElementTransform.Height;


            Focus.FocusElls.ScopeRectangle.Width = rightTriangleElement.ElementTransform.Width;
            Focus.FocusElls.ScopeRectangle.Height = rightTriangleElement.ElementTransform.Height;
            Focus.SetFocuseEllipseMargin(rightTriangleElement.ElementTransform.Width, rightTriangleElement.ElementTransform.Height);

            Point[] pt = new Point[rightTriangleElement.Points.Count];
            PointCollection pts = new PointCollection();
            rightTriangleElement.Points.CopyTo(pt, 0);
            pt[0].X = 0;
            pt[0].Y = 0;
            pt[1].X = rightTriangleElement.ElementTransform.Width;
            pt[1].Y = rightTriangleElement.ElementTransform.Height;
            pt[2].X = 0;
            pt[2].Y = rightTriangleElement.ElementTransform.Height;
            pts.Add(pt[0]);
            pts.Add(pt[1]);
            pts.Add(pt[2]);
            rightTriangle.Points = pts;
            rightTriangleElement.Points = pts;
        }
    }
}
